home *** CD-ROM | disk | FTP | other *** search
- Path: power2.powernet.co.uk!usenet
- From: dean@bugboy.powernet.co.uk (Dean Barrett)
- Newsgroups: comp.lang.c++
- Subject: Newbie help please !!!!!!
- Date: Fri, 16 Feb 1996 18:57:53 GMT
- Organization: Power Internet
- Message-ID: <4g2k9s$895@power2.powernet.co.uk>
- Reply-To: dean@bugboy.powernet.co.uk
- NNTP-Posting-Host: bugboy.powernet.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Can any body please help with probably a very simple problem,
- part of program below shows data being written to then retreaved from
- file - I can get data to disk fine with each item on seperate lines
- but when i retreive it all goes horribly wrong!!. If i use
- From_file<< to get data it works like cin so I lose strings with
- spaces - book im reading says you can use gets() and puts() to
- write data but I cant work this out - any help greatly appreciated
- please email dean@bugboy.powernet.co.uk --
-
- thanks in anticipation.
-
- Dean Barrett.
-
- void Bank_account::File_write()
- {
- //data below obtained using gets and cin from user..
- To_file.open(Acc_no,ios::out);
- strcat(Acc_no,"\n");
- strcat(Name,"\n");
- strcat(Address,"\n");
- To_file<<Acc_no;
- To_file<<Name;
- To_file<<Address;
- To_file<<Balance;
- To_file.close();
- };
-
-
- void Bank_account::File_get()
- {
- //Tried this From_file get but doesnt work quite right
- char Delim='\n';
- cout<<"Enter account No.\n";
- cin>>Acc_no;
- From_file.open(Acc_no,ios::in);
- if (From_file.good())
- {
-
- From_file.get(Acc_no,9,Delim);
- cout<<Acc_no<<"\n";
- From_file.get(Name,25,Delim);
- cout<<Name<<"\n";
- From_file.get(Address,40,Delim);
- cout<<Address<<"\n";
- From_file>>Balance;
- cout<<Balance<<"\n";
- From_file.close();
- }
- else
- {
- cout<<"This account does not exist\ncreate new \n";
- cout<<"Enter name\n";
- cout.flush();
- gets(Name);
- cout<<"Enter 1st line of address\n";
- cout.flush();
- gets(Address);
- fflush(stdin);
- cout<<"Enter opening Balance\n";
- cin>>Balance;
- cout.flush();
- fflush(stdin);
-
- }
-
-
-
- };
-
-
-
-